package stark.app.function.paint;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vilyever.drawingview.db.DrawRecord;
import com.vilyever.drawingview.db.DrawRecordDbUtil;

import java.util.List;

import stark.app.R;
import stark.app.base.BaseWithFragmentActivity;
import stark.app.databinding.ActivityPaintDemoBinding;
import stark.common.basic.base.BaseNoModelActivity;

/**
 * Author：daizhongbin on 2021/11/13
 * Email：1027154338@qq.com
 * Desc:
 */
public class PaintDemoActivity extends BaseNoModelActivity<ActivityPaintDemoBinding> {

    private DrawRecordAdapter mAdapter;
    @Override
    protected int onCreate() {
        return R.layout.activity_paint_demo;
    }

    @Override
    protected void initView() {
        mDataBinding.btnPaint.setOnClickListener(v -> {
            BaseWithFragmentActivity.start(this, "画板", DrawingFragment.class);
        });
        GridLayoutManager layoutManager = new GridLayoutManager(this, 3);
        mDataBinding.rvDrawRecord.setLayoutManager(layoutManager);
        mAdapter = new DrawRecordAdapter();
        mAdapter.setOnItemClickListener(this);
        mDataBinding.rvDrawRecord.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
    }

    @Override
    protected void onResume() {
        super.onResume();
        List<DrawRecord> records = DrawRecordDbUtil.getDrawRecords(0, 100);
        mAdapter.setNewInstance(records);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        Bundle bundle = new Bundle();
        DrawRecord record = mAdapter.getItem(position);
        bundle.putSerializable(DrawingFragment.KEY_DRAW_RECORD, record);
        BaseWithFragmentActivity.start(this, "画板", DrawingFragment.class, bundle);
    }
}
